<?php

namespace App\Models;

class StSgBlackList extends StModel
{
    protected $table = 'st_sg_black_list';// 上工回调表

    protected $primaryKey = 'id';

    public function addOneHospital($hospitalId)
    {
        $updateWhere = [
            'hospital_id' => $hospitalId,
            'status' => 0,
            'type' => 1,
        ];
        $count = $this->countBy($updateWhere);

        if ($count) {
            $res = $this->updateBy(['status' => 1], $updateWhere);
        } else {
            $res = $this->insert_db([
                'hospital_id' => $hospitalId,
                'status' => 1,
                'type' => 1,
            ]);
        }

        return $res;
    }

    public function isExitHospital($hospitalId)
    {
        $count = $this->countBy([
            'hospital_id' => $hospitalId,
            'status' => 1,
            'type' => 1,
        ]);

        return $count >= 1 ? 1 : 0;
    }

    public function addOneDoctor($doctorId)
    {
        $updateWhere = [
            'doctor_id' => $doctorId,
            'status' => 0,
            'type' => 2,
        ];
        $count = $this->countBy($updateWhere);

        if ($count) {
            $res = $this->updateBy(['status' => 1], $updateWhere);
        } else {
            $res = $this->insert_db([
                'doctor_id' => $doctorId,
                'status' => 1,
                'type' => 2,
            ]);
        }

        return $res;
    }

    public function isExitDoctor($doctorId)
    {
        $count = $this->countBy([
            'doctor_id' => $doctorId,
            'status' => 1,
            'type' => 2,
        ]);

        return $count >= 1 ? 1 : 0;
    }
}